from django.template import Library
from django.template.context import Context, RequestContext, ContextPopException
from django.template.loader import get_template, select_template

register = Library()

def xadmin_theme():
    """
    Returns the string contained in the setting ADMIN_MEDIA_PREFIX.
    """    
    try:
        from xadmin import settings
    except ImportError:
        return ''
    return settings.THEME
xadmin_theme = register.simple_tag(xadmin_theme)


def xadmin_button(label, link, icon=None):
    ctx =  {'label': label, 
            'url' : link,
            'icon' : "ui-icon " + icon if icon else ""
            }
    t = get_template('xadmin/inlines/ui_button.html')
    return t.render(Context(ctx))


xadmin_button = register.simple_tag(xadmin_button)